using AppToolKit.Core;
using AppToolKit.Core.AttributeDiscovery;
using AppToolKit.Core.Context;
using AppToolKit.Core.Logging;
using Common.Logging;
using System;
using System.Reflection;
namespace AppToolKit.Business.Observer
{
	public class ObserveAttrProcessor : IFeatureProcessor
	{
		private static ILog logger_ = LogManager.GetLogger(DefaultLogger.LOGGER_NAME);
		public IObserverManager ObserveMgr
		{
			get;
			set;
		}
		public IContextManager ContextMgr
		{
			get;
			set;
		}
		public bool IsSupport(Assembly assembly)
		{
			return assembly.IsDefined(typeof(BussinessAssemblyAttribute), true);
		}
		public void Process(Type type, FeatureProcessContext ctx)
		{
			if (ObserveAttrProcessor.logger_.IsDebugEnabled)
			{
				ObserveAttrProcessor.logger_.Debug(string.Format("Check Observe {0} ", type));
			}
			if (type.IsDefined(typeof(ObserverAttribute), false) && TypeHelper.IsInheritInterface(type, typeof(IObserver)))
			{
				ObserveAttrProcessor.logger_.Debug(string.Format("find observe{0}", type.FullName));
				if (!this.ContextMgr.IsSingleton(type))
				{
					throw new ObserveException(string.Format("{0}必须是singleton", type));
				}
				object @object = this.ContextMgr.GetObject(type);
				IObserver observer = (IObserver)@object;
				observer.Register(this.ObserveMgr);
			}
		}
		public void ProcessAssembly(Assembly assembly)
		{
		}
	}
}
